﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using LanguageInfo.Common.Utilities;
using System.Data;
using LanguageInfo.Entity;
using LanguageInfo.Common.Enum;

namespace LanguageInfo.BLL
{
    public class BasePage : Page
    {
        #region 模块ID
        /// <summary>
        /// 模块ID
        /// </summary>
        public virtual string StrPageUrl
        {
            get
            {
                return string.Empty;
            }
        }
        #endregion

        #region 页面初始化
        public BasePage()
        {
            this.Init += new EventHandler(BasePage_Init);
        }

        /// <summary>
        /// 页面初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void BasePage_Init(object sender, EventArgs e)
        {
            UserInfo CurrentUser = UserInfoBLL.SessionUserInfo;
            if (CurrentUser == null)
            {
                UserInfoBLL.Logout();
                Response.Redirect(string.Format("~/Error.aspx?errortype={0}", (int)CommonEnum.ErrorType.NoRight));
            }

            if (!UserInfoBLL.IsRole(this.StrPageUrl, CurrentUser.Role))
            {
                
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "window.top.location.href='" + Page.ResolveClientUrl(string.Format("~/Error.aspx?errortype={0}", (int)CommonEnum.ErrorType.NoRight)) + "';", true);

                //Response.Redirect(string.Format("~/Error.aspx?errortype={0}", (int)CommonEnum.ErrorType.NoRight));
            }

            //权限控制
            this.AccessControl();
        }
        #endregion

        #region 在客户端显示信息的方法
        /// <summary>
        /// 显示客户端消息
        /// </summary>		
        /// <param name="message">消息内容</param>
        public void ShowAlert(string message)
        {

            ClientScript.RegisterStartupScript(typeof(string), Guid.NewGuid().ToString(), string.Format("<script language=javascript>alert(\"{0}\");</script>", StringHelper.ScriptStr(message)));
        }
        #endregion

        #region 权限控制
        protected virtual void AccessControl()
        {
        }

        #endregion

    }
}
